<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.brooklynmarathon.checkout.Util" %>
<%@ page import="com.brooklynmarathon.checkout.Customer" %>
<%@ page import="com.brooklynmarathon.checkout.PMF" %>

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
  </head>

  <body>

<%
try
{
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
%>
<p>Hello, <%= user.getNickname() %>! (You can
<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
<%
    } else {
%>
<p>Hello!
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
to include your name with Customers you post.</p>
<%
    }
%>

<%
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + Customer.class.getName() + " order by date desc range 0,10";

    List<Customer> Customers = (List<Customer>) pm.newQuery(query).execute();

    if (Customers.isEmpty()) {
%>
<p>no messages.</p>
<%
    } else {

    %>
    <table class="sample">
	<tr>
	    <th>Date</th>
	    <th>TransactionId</th>
	    <th>Period</th>
	    <th>Reason</th>
	    <th>Recipient Token</th>
	    <th>Caller Reference</th>
	    <th>Times</th>
	    <th>Amount</th>
	</tr>
    <%

        for (Customer g : Customers) {
%>
<tr class="d0">
    <td> <%= g.getDate() %>  </td>
    <td> <%= g.getTransactionId() %> </td>
    <td> <%= g.getPeriod() %> </td>
    <td> <%= g.getReason() %> </td>
    <td> <%= g.getRec_token() %> </td>
    <td> <a href="/queuelist.jsp?callerReference=<%= g.getCallerReference() %>"><%= g.getCallerReference() %></a> </td>
    <td> <%= g.getTimes() %> </td>
    <td> <%= g.getAmount() %> </td>

    </tr>



<%
        }
	%>
    </table>

<%
    }
    pm.close();

    }
    catch (Exception e)
    {
    %>
    Error: <%=e.getMessage()%>
    <%
    }
%>


  </body>
</html>
